﻿//********************************************************************************//
//创建日期：<创建日期，2017-09-19>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：立成财务接口(自来水)
//********************************************************************************//
layui.use(['form', 'jquery', 'element', 'laydate'], function () {
    var form = layui.form()
    , layer = layui.layer
    , $ = layui.jquery
    , element = layui.element()
    , laydate = layui.laydate;
    /*initial load start*/
    initcontrol();
    /*initial load end*/

    /*initial*/
    function initcontrol() {
        //设置默认打印日期与回执日期
        //var date = new Date();
        //var year = date.getFullYear();
        //var month = date.getMonth() + 1;
        //var day = date.getDate();
        //$("#c2DYRQ").val(year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day));
        //获取当前账务年月
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/Common.ashx",
            data: {
                "op": "YSZWYM"
            },
            dataType: "json",
            success: function (rs) {
                $("#cZWYM").val(rs.Data1);
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });

    }
    /*end initial*/

    /*event*/
    $("#oSCSJ").click(function () {
        if ($("#cZWYM").val() == "") {
            layer.alert("请填写账务年月");
            return;
        }
        var index = layer.load(1);
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/QSSFZW/LCCWJK.ashx",
            data: {
                "op": "SC",
                "zwym": $("#cZWYM").val()
            },
            dataType: "json",
            success: function (rs) {
                if (rs.State) {
                    layer.alert('生成成功', function (index1) {
                        loadPZXX();
                        loadMX(0);
                        layer.close(index1);
                    });
                }
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
        layer.close(index);
    });
    function loadPZXX()
    {
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/QSSFZW/LCCWJK.ashx",
            data: {
                "op": "PZXX_HQ",
                "zwym": $("#cZWYM").val()
            },
            dataType: "json",
            success: function (rs) {
                var strs = "";
                $("#ContentList1 .datarow").remove();
                for (var i = 0; i < rs.length; i++) {
                    strs = strs + "<tr class='datarow' style='cursor:pointer' vid='" + rs[i]["I_PINGZHENGLXBH"] + "'><td>" + rs[i]["I_PINGZHENGLXBH"] + "</td><td>" + rs[i]["S_PINGZHENGLX"] + "</td></tr>";
                }
                $("#ContentList1").append(strs);
                //绑定左侧凭证信息点击加载
                $("#ContentList1 .datarow").click(function () {
                    var lxbhT = $(this).attr("vid");
                    loadMX(lxbhT);
                });
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
    }
    function loadMX(pzlxbh) {
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/QSSFZW/LCCWJK.ashx",
            data: {
                "op": "HQ",
                "zwym": $("#cZWYM").val(),
                "pzlxbh":pzlxbh
            },
            dataType: "json",
            success: function (rs) {
                var strs = "";
                $("#ContentList2 .datarow").remove();
                for (var i = 0; i < rs.length; i++) {
                    var str = "<tr class='datarow'>"
                                        + "<td>" + rs[i]["S_GONGZUONY"] + "</td>"
                                        + "<td>" + rs[i]["I_PINGZHENGLXBH"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["I_SHOUFUZJLX"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["I_XIANYINZJLX"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["S_KEMUDM"] + "</td>"
                                        + "<td>" + rs[i]["N_JIEFANGJE"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["N_DAIFANGJE"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["S_KEHUDM"] + "</td>"
                                        + "<td>" + rs[i]["S_KEHUMC"] + "</td>"
                                        + "<td>" + rs[i]["I_FENLUSXH"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["S_BEIZHU"] + "</td>"
                                        + "<td>" + rs[i]["S_ZHAIYAO"] + "</td>"
                                        + "<td>" + rs[i]["N_WAIBIJFJE"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["N_WAIBIDFJE"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["N_HUILV"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["N_JIEFANGSL"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["N_DAIFANGSL"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["N_DANJIA"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["S_FAPIAOBH"] + "</td>"
                                        + "<td>" + rs[i]["S_JIESUANFS"] + "</td>"
                                        + "<td>" + rs[i]["S_PIAOJUBH"] + "</td>"
                                        + "<td>" + rs[i]["S_BIZHONG"] + "</td>"
                                        + "<td>" + rs[i]["D_PINGZHENGLRRQ"]["DateString"] + "</td>"
                                        + "<td>" + rs[i]["S_HESUANDM"] + "</td>"
                                        + "<td>" + rs[i]["S_RENYUANDM"] + "</td>"
                                        + "<td>" + rs[i]["S_DANJUBH"] + "</td>"
                                        + "<td>" + rs[i]["S_PINGZHENGBH"] + "</td>"
                                        + "<td>" + rs[i]["S_ZHIDAN"] + "</td>" 
                                        + "<td>" + rs[i]["I_FUJIAN"]["ValueString"] + "</td>"
                                        + "<td>" + rs[i]["S_FUHE"] + "</td>"
                                        + "<td>" + rs[i]["D_SHIJIRQ"]["DateString"] + "</td>"
                                        + "<td>" + rs[i]["S_XIANGMDM"] + "</td>"
                                        + "<td>" + rs[i]["S_XIANGMUMC"] + "</td></tr>"
                    ;
                    strs = strs + str;     }
                $("#ContentList2").append(strs);
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
    }
    
    $("#oDRLC").click(function () {
        if($("#cZWYM").val()=="")
        {
            layer.alert("请输入账务年月");
            return;
        }
        if($("#ContentList1 .datarow").length==0)
        {
            layer.alert("没有可导入的数据");
            return;
        }
        $.ajax({
            type: "post",
            cache: false,
            async: false,
            url: "/ashx/QSSFZW/LCCWJK.ashx",
            data: {
                "op": "DRLC",
                "zwym": $("#cZWYM").val()
            },
            dataType: "json",
            success: function (rs) {
                //layer.alert("操作成功");
                layer.alert(rs.Msg);
            },
            error: function (error) {
                layer.msg(error.responseText);
            }
        });
    });
    
    $("#cZWYM").keypress(function () {
        if (event.keyCode == 13) {
            setTimeout(function () {

            }, 0);
            event.preventDefault ? event.preventDefault() : (event.returnValue = false);
            var index = layer.load(1);
            loadPZXX();
            loadMX(0);
            layer.close(index);
        }
    });
    //$("body").keypress(function () {        
    //    if(event.keyCode==13)
    //    {
    //        setTimeout(function () {

    //        }, 0);
    //        event.preventDefault ? event.preventDefault() : (event.returnValue = false);
    //        layer.closeAll();
    //    }
    //});
    /*event end*/

    function verify() {
        return true;
    }

    /*logic end*/
});